
package net.pec.geotools_svg.svg_conversion;


import java.io.*;
import java.net.URL;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.geotools.data.*;
import org.geotools.feature.*;
import org.opengis.feature.simple.SimpleFeature;

import com.vividsolutions.jts.geom.*;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class GenerateArrowPolylineElement {

private static double middleY;
private boolean evenOdd = true;
private String pointValues = "";

  
public Element getFeature(SimpleFeature feature, Document doc, Element gElement, 
		Double midpoint, int strokeRed, int strokeGreen, int strokeBlue,  double strokeopacity, 
		String strokewidth, String clickEvent, Double viewboxSize, int percLength, int Angle  ) throws Exception {
	
  middleY = midpoint;
  
  String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
  Element polylineElement = doc.createElementNS(svgNS, "polyline");
  polylineElement.setAttributeNS(null, "id", feature.getID());
  polylineElement.setAttributeNS(null, "style","fill:none;stroke:rgb("+strokeRed+","+strokeBlue+","+strokeGreen+")" +
  		";stroke-width:"+strokewidth+";stroke-opacity:"+strokeopacity);
  polylineElement.setAttributeNS(null, "marker-end", "url(#MidMarker)");
  
  
  if (clickEvent !=null){
	  polylineElement.setAttributeNS(null, "onclick", clickEvent);
  }
  
  Geometry geom = (Geometry) feature.getDefaultGeometry();
  
 
  Coordinate oneCrd = geom.getCoordinate();
  double coorddiff = oneCrd.y - midpoint;
  double newcoord = midpoint-coorddiff;
  polylineElement.setAttributeNS(null,"transform","rotate("+(360-Angle)+","+oneCrd.x+","+newcoord+")");
  
  pointValues = pointValues+oneCrd.x + "," + newcoord + " ";
  pointValues = pointValues+oneCrd.x + "," + (newcoord-getLength(viewboxSize, percLength)) + " ";
  
  polylineElement.setAttributeNS(null, "points", pointValues);
  return polylineElement;
			  
}

private Double getLength(Double widthHeight, int percLength){		
	Double length = widthHeight*((double)percLength/100);
	//offset=offset/2;
	return length;
}
	  
	 
	  

}